package manager

import (
	"nprobe/core"
	"nprobe/core/agent"
	"nprobe/core/icmp"
	"nprobe/core/tcp"
	"nprobe/core/tcpserver"
	"nprobe/core/tcpsyn"
	"nprobe/core/udp"
	"nprobe/core/udpecho"
	"nprobe/core/udpserver"
)

func NewAgent(task *core.ProbeTask) (agent.Agent, error) {
	var err error
	var agent agent.Agent
	if task.Proto == "icmp" {
		agent, err = icmp.NewICMPAgent(task.Proto, task)
	} else if task.Proto == "udp" && task.Role == "client" && !task.WithEchoServer {
		agent, err = udp.NewUDPAgent(task.Proto+"-"+task.Role, task)
	} else if task.Proto == "udp" && task.Role == "client" && task.WithEchoServer {
		agent, err = udpecho.NewUDPEchoAgent(task.Proto+"-echo", task)
	} else if task.Proto == "udp" && task.Role == "server" {
		// udp server
		agent, err = udpserver.NewUDPServerAgent(task.Proto+"-"+task.Role, task)
	} else if task.Proto == "tcpsyn" {
		// tcp syn
		agent, err = tcpsyn.NewTCPSYNAgent(task.Proto+"-"+task.Role, task)
	} else if task.Proto == "tcp" && task.Role == "client" {
		// tcp client
		agent, err = tcp.NewTCPAgent(task.Proto+"-"+task.Role, task)
	} else if task.Proto == "tcp" && task.Role == "server" {
		// tcp server
		agent, err = tcpserver.NewTCPServerAgent(task.Proto+"-"+task.Role, task)
	}

	return agent, err
}
